<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
            "maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>追派</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/rams.css"/>
    <style>
    .aui-bar-nav{
        background-color: #e10010;
    }
    .aui-icon-left{
        font-size: 0.7rem;
        font-weight: 700;
    }
    select {

        text-align: left;

        text-align-last: left;

    }

    </style>
</head>
<body >
<div class="bodyContainer bodyPosition">
    <header class="aui-bar aui-bar-nav headerMarginTop">
        <div class="aui-pull-left aui-btn">
            <span class="aui-iconfont aui-icon-left"></span><span class="aui-Font" onclick="api.closeWin()">返回</span>
        </div>
        <div class="aui-title">追派</div>
        <div class="aui-pull-right header_confirm">
            <span class="aui_Font" onclick="save()">确定</span>
        </div>
    </header>
    <div>
        <div id="workSheet_area" class="aui-padded-l-15">
            <!--追派类型-->
            <div class="workSheet_Choose_div">
                <div  class="workSheet_Choose_div_sp">
                    <div class="inline-block" style="width: 30%;">
                        <span class="redStar">*</span>
                        追派类型：
                    </div>
                    <div class="inline-block" style="width: 50% ">
                        <select id="disposeWay">
                            <option value='' disabled selected style='display:none;'>请选择</option>
                        </select>
                    </div>
                    <div  class="inline-block lianTong-icon-down" >
                        <span class="aui-iconfont aui-icon-down rams-float-right" ></span>
                    </div>
                </div>
                <div class="greyLine96"></div>
            </div>
            <!--追派对象-->
            <div class="workSheet_Choose_div">
                <div  class="workSheet_Choose_div_sp" style="padding-top: 0.55rem">
                    <div class="inline-block" style="width: 30%;">
                        <span class="redStar">*</span>
                        追派对象：
                    </div>
                    <div class="inline-block" style="width: 50%;">
                        <input onclick="openWin(this)" id="zpdx" name="" placeholder="请选择">
                    </div>
                    <div  class="inline-block lianTong-icon-down" >
                        <span class="aui-iconfont aui-icon-down rams-float-right" ></span>
                    </div>
                </div>
                <div class="greyLine96"></div>
            </div>
            <!--抄送对象-->
            <div class="workSheet_Choose_div">
                <div  class="workSheet_Choose_div_sp" style="padding-top: 0.55rem">
                    <div class="inline-block" style="width: 30% ">
                        <span class="whiteStar">*</span>
                        抄送对象：
                    </div>
                    <div class="inline-block" style="width: 50% ">
                        <input onclick="openWin(this)" id="csdx" name="" placeholder="请选择">
                    </div>
                    <div  class="inline-block lianTong-icon-down" >
                        <span class="aui-iconfont aui-icon-down rams-float-right" ></span>
                    </div>
                </div>
                <div class="greyLine96"></div>
            </div>
            <!--追派原因-->
                <div class="infoMarginTop">
                    <div>
                        <span class="whiteStar">*</span>
                        追派原因：
                    </div>
                    <div>
                        <textarea  placeholder="请输入" id="remark"></textarea>
                    </div>
                </div>
        </div>
    </div>
</div>
<script id="type-selector" type="text/template">
    <option value=""  disabled selected >请选择</option>
    {{ for(var i=0;i<it.nameList.length;i++){
        if(!common.isEmpty(it.nameList[i])){
    }}
    <option value="{{=it.idList[i]}}">{{=it.nameList[i]}}</option>
    {{
        }
    }
    }}
</script>
<script>
    var inputId = '';
    var zpdxId = "";
    var csdxId = "";
    var zpdxType = "";
    var csdxType = "";
    apiready = function() {
        initSelect()

        //监听登出事件
        api.addEventListener({
            name: 'loginout'
        }, function(ret, err) {

            var id = $api.getStorage(storageKey.data_id);
            var name = $api.getStorage(storageKey.data_name);
            var type = $api.getStorage(storageKey.data_type);

            //对象获取值
            $api.val($api.byId(inputId),name);
            if (inputId == "zpdx") {
                zpdxId = id;
                zpdxType = type;
            } else if (inputId == "csdx") {
                csdxId = id;
                csdxType = type;
            }

            $api.rmStorage(storageKey.data_id);
            $api.rmStorage(storageKey.data_name);
            $api.rmStorage(storageKey.data_type);
        });
    }

    //动态加载select
    function initSelect(){
        common.post({
            url : config.getAllIdUrl  ,
            isLoading:false,
            data:{
                parentdictid:parentdictid.appendWorksheet
            },
            success : function(ret){
                if(ret&&ret.status==='200'){
                    //填写信息
                    if (ret.data&&ret.data.name&&ret.data.id&&ret.data.name.length > 0) {
                        var data = ret.data;
                        var strName = (data.name).split(",");    //字符分割;
                        var strId  = (data.id).split(",");    //字符分割;
                        var params = {
                            idList:[],
                            nameList:[]
                        }
                        params.idList = strId
                        params.nameList = strName
                        $api.html($api.byId('disposeWay'), "");
                        var disposeWay = doT.template($api.text($api.byId('type-selector')));
                        $api.html($api.byId('disposeWay'), disposeWay(params));
                    }else {
                        api.alert({
                            msg:'没有可用的追派类型！'
                        })
                    }
                }else {
                    api.toast({
                        msg: '获取追派类型失败！',
                        duration: config.duration,
                        location: 'middle'
                    });
                }
            }
        });
    }
    function openWin(ele) {
        inputId = $api.attr(ele,'id');
        api.openWin({
            name: 'tag_tree',
            bounces: false,
            slidBackEnabled : false,
            reload:true,
            url: '../../html/malfunction/my_tree.html',
            vScrollBarEnabled:true,
            hScrollBarEnabled:false

        });

    }

    function save() {
        var chuliGroupd = csdxId;                                       //抄送对象
        var chuliGroupdType = csdxType;                                        //抄送对象类型
        var dispose_way = $("#disposeWay option:selected").val();         //追派类型
        if(common.isEmpty(dispose_way)){
            api.toast({
                msg: '请选择追派类型',
                duration: config.duration,
                location: 'middle'
            });
            return;
        }

        var paiwangGroupd = zpdxId;                                     //追派对象
        var paiwangGroupdType = zpdxType;                                     //追派对象类型
        if( common.isEmpty(paiwangGroupd)){
            api.toast({
                msg: '请选择追派对象',
                duration: config.duration,
                location: 'middle'
            });
            return;
        }

        var wsNum = $api.getStorage(storageKey.wsNum);                  //工单号
        var processId = $api.getStorage(storageKey.processId);          //流程id
        var remark = $api.trim($api.val($api.byId('remark')));            //追派原因

        api.confirm({
            title: '追派',
            msg: '是否提交？',
            buttons: ['确定', '取消']
        }, function(retBtn, err) {
            if(retBtn.buttonIndex===1){
                common.post({
                    url:config.appendWorksheetUrl,
                    isLoading: true,
                    text: "提交中...",
                    data:{
                        wsNum : wsNum,
                        remark : remark,
                        paiwangGroupd : paiwangGroupd,
                        paiwangGroupdType : paiwangGroupdType,
                        processId : processId,
                        chuliGroupd : chuliGroupd,
                        chuliGroupdType : chuliGroupdType,
                        dispose_way : dispose_way
                    },
                    success: function (ret) {
                        if (ret.status==='200'){
                            api.alert({
                                title: '提示',
                                msg: '追派操作成功！',
                            }, function (ret, err) {
                                common.closeAndReloadAppointPage('process_success_reload_worksheet_detail');
                            });
                        } else {
                            var msg = '追派操作失败！'
                            if (ret&&ret.data&&ret.data.message){
                                msg = ret.data.message
                            }
                            api.toast({
                                msg:  msg,
                                duration: config.duration,
                                location: 'middle'
                            });
                        }
                    }
                });
            }
        });
    }
</script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/doT.min.js"></script>
<script type="text/javascript" src="../../script/malfunction/jquery-3.2.1.js"></script>
<script type="text/javascript" src="../../script/config.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
</body>
</html>
